#!/usr/bin/bash

# basename 获取 /home/zhangming/gitspace/shell-learning/variables 最后一段 variables
# dirname  获取 /home/zhangming/gitspace/shell-learning/variables 前面一段 /home/zhangming/gitspace/shell-learning
if [ $# -eq 0 ];then
    echo "usage: `basename $0` file"
    exit
fi

if [ ! -f $1 ];then
    echo "$1 is not file"
    exit
fi

for ip in `cat $1`
do
    ping -c1 $ip &>/dev/null
    if [ $? -eq 0 ];then 
        echo "$ip is up"
    else
        echo "$ip is down"
    fi
done
